package com.ids.idtma.adapter;
	import java.io.IOException;

	import android.media.AudioManager;
	import android.media.MediaPlayer;
	import android.media.MediaPlayer.OnErrorListener;

	//播放录音的类
	public class RecoderPlayer {

	    private static MediaPlayer mMediaPlayer;
	    private static boolean isPause = false;//是否为暂停播放
	    
	    //播放音乐
	    public void playSound(String filePath) {

	        if(mMediaPlayer == null){

	            mMediaPlayer = new MediaPlayer();
	            mMediaPlayer.setOnErrorListener(new OnErrorListener() {

	                public boolean onError(MediaPlayer mp, int what, int extra) {

	                    mMediaPlayer.reset();
	                    return false;
	                }
	            });
	        }else{
	            mMediaPlayer.reset();

	        }

	        try {
	            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
	            mMediaPlayer.setDataSource(filePath);
	            mMediaPlayer.prepare();
	            mMediaPlayer.start();
	        } catch (IllegalArgumentException e) {
	            e.printStackTrace();
	        } catch (SecurityException e) {
	            e.printStackTrace();
	        } catch (IllegalStateException e) {
	            e.printStackTrace();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }

	    }

	    //暂停播放
	    public static void pause(){

	        if(mMediaPlayer != null && mMediaPlayer.isPlaying()){
	            mMediaPlayer.pause();
	            isPause = true;
	        }

	    }

	    //复位播放

	    public static void reset(){

	        if(mMediaPlayer != null && isPause){

	            mMediaPlayer.start();
	            isPause = false;
	        }
	    }

	    //释放资源
	    public static void release(){

	        if(mMediaPlayer != null){
	            mMediaPlayer.release();
	            mMediaPlayer = null;
	        }
	    }

	}
